import { Notify } from 'quasar'

/** @mixin iDefaultOptions */
const defaultOptions = {
  errCallback: msg => {
    console.log('errCallback', msg)
  },
  onResponseFail (msg) {
    Notify.create({
      position: 'top',
      type: 'negative',
      color: 'negative',
      message: msg
    })
  },
  successHandler (res) {
    if (res.code === 2) {
      location.href = '/login'
    }
    if (res.code !== 0) {
      Notify.create({
        position: 'top',
        type: 'negative',
        color: 'negative',
        message: res.msg
      })
    }
    return {
      success: res.code === 0,
      data: res.data,
      msg: res.msg
    }
  },
  merge: true,
  baseURL: process.env.baseApi,
  withCredentials: true
}

export default defaultOptions
export { defaultOptions }
